package com.chinatsp.filter;

import com.chinatsp.util.StringUtils;
import org.apache.log4j.Logger;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author 高林发
 * @version 创建时间：2012-7-10 下午03:02:29
 * 重要接口，统一所有request请求的编码
 */
public class InitFilter implements Filter {
	private Logger log = Logger.getLogger("api.access");
	public void destroy() {
		
	}

	/**
	 * 处理所有对接口的请求，将编码格式统一为UTF-8
	 */
	public void doFilter(ServletRequest request, ServletResponse response,
						 FilterChain filterChain) throws IOException, ServletException {
		if(StringUtils.isEmpty(request.getCharacterEncoding())){
			request.setCharacterEncoding("UTF-8");
		}
		if(StringUtils.isEmpty(response.getCharacterEncoding())){
			response.setCharacterEncoding("UTF-8");
		}

		filterChain.doFilter(request, response);
	}
	
	@Override
	public void init(FilterConfig arg0) throws ServletException {

	}

}
